from django.db import models
from cmdb.models import DeviceInfo, Business, Label


class TimeAbstract(models.Model):
    add_time = models.DateTimeField(auto_now_add=True, verbose_name="添加时间")
    modify_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        abstract = True


class Project(TimeAbstract):
    """
    项目配置表
    """
    name = models.CharField(default='', max_length=100, verbose_name='项目名称')
    alias = models.CharField(default='', max_length=100, verbose_name='别名')
    git_url = models.CharField(default='', max_length=200, verbose_name='git仓库地址')
    branch = models.CharField(default='', max_length=50, verbose_name='git分支')
    version_num = models.IntegerField(blank=True, null=True, verbose_name='版本号')
    environment = models.CharField(default='', max_length=30, verbose_name='环境')
    status = models.CharField(max_length=20, blank=True, null=True, verbose_name="状态")
    compile_path = models.CharField(default='', max_length=200, verbose_name='编译路径')
    compile_output_path = models.CharField(default='', max_length=200, verbose_name='编译输出路径')
    device_info_id = models.ForeignKey(DeviceInfo, null=True, blank=True, on_delete=models.SET_NULL,
                                       verbose_name="设备信息id")
    business_id = models.ForeignKey(Business, null=True, blank=True, on_delete=models.SET_NULL,
                                       verbose_name="业务类型id")
    label_id = models.ForeignKey(Label, null=True, blank=True, on_delete=models.SET_NULL,
                                       verbose_name="设备标签/项目类型id")
    user_id = models.CharField(max_length=100, default='', blank=True, null=True, verbose_name='关联用户id')

    class Meta:
        verbose_name = '项目配置'
        verbose_name_plural = verbose_name
